#mapping-script
# -*- coding: ms949 -*-
import bots.transform as transform
import bots.usersys.mappings.utils as utils

def main(inn,out):
    #XML
    ns1 = '{urn:kr:gov:kcs:data:standard:KCS_ListReportOfReleaseNoticeSchemaModule:1:0:0}'
    ns2 = '{urn:kr:gov:kcs:common:standard:KCS_ReusableAggregateBusinessInformationEntitySchemaModule:1:0:0}'
    rootelement = ns1 + 'ListReportOfReleaseNotice'
    
    #Read from inn by EDIFACT order
    
    DocumentTypeCode = inn.get({'BOTSID':'UNH'},{'BOTSID':'BGM','C002.1001':None})
    UCRIdentificationID = inn.get({'BOTSID':'UNH'},{'BOTSID':'BGM','1004':None})
    DocumentFunctionTypeCode = inn.get({'BOTSID':'UNH'},{'BOTSID':'BGM','1225':None})
    DocumentIssueDate = inn.get({'BOTSID':'UNH'},{'BOTSID':'DTM','C507.2005':'108','C507.2380':None})
    ScheduledOverdueGoodsDate = inn.get({'BOTSID':'UNH'},{'BOTSID':'DTM','C507.2005':'206','C507.2380':None})
    CustomsOfficeCodeID = inn.get({'BOTSID':'UNH'},{'BOTSID':'LOC','C517.1131':'113','C517.3225':None})
    CustomsOfficeCode = inn.get({'BOTSID':'UNH'},{'BOTSID':'LOC','C519.1131':'5AB','C519.3223':None})
    WarehouseCodeID = inn.get({'BOTSID':'UNH'},{'BOTSID':'LOC','3227':'14','C517.1131':'129','C517.3225':None})
    AssociatedTransportDocumentReferenceID = inn.get({'BOTSID':'UNH'},{'BOTSID':'RFF','C506.1153':'BM','C506.1154':None})
    
    ConsignorPartyID = inn.get({'BOTSID':'UNH'},{'BOTSID':'NAD','3035':'GO','C082.1131':'174','C082.3039':None})
    ConsignorPartyName = inn.get({'BOTSID':'UNH'},{'BOTSID':'NAD','3035':'GO','C080.3036#1':None})
    ConsignorPartyCommunicationAddressID = inn.get({'BOTSID':'UNH'},{'BOTSID':'NAD','3035':'GO','C059.3042#1':None})
    ConsignorPartyCommunicationAddressID2 = inn.get({'BOTSID':'UNH'},{'BOTSID':'NAD','3035':'GO','C059.3042#2':None})
    if ConsignorPartyCommunicationAddressID2 != None: ConsignorPartyCommunicationAddressID = ConsignorPartyCommunicationAddressID + ' ' + ConsignorPartyCommunicationAddressID2
    ConsignorPartyAddressPostalCodeID = inn.get({'BOTSID':'UNH'},{'BOTSID':'NAD','3035':'GO','3251':None})
    ConsignorPartyCommunicationTelephone = inn.get({'BOTSID':'UNH'},{'BOTSID':'NAD'},{'BOTSID':'CTA'},{'BOTSID':'COM','C076.3155':'TE','C076.3148':None})
    CarryInGoodsPackagingQuantity = inn.get({'BOTSID':'UNH'},{'BOTSID':'GID','C213#1.7224':None})
    CarryInMeasure = inn.get({'BOTSID':'UNH'},{'BOTSID':'GID'},{'BOTSID':'MEA','6311':'WT','C174.6411':'KG','C174.6314':None})
    
    
    out.ta_info['botskey'] = 'CUSCAR-5II-' + UCRIdentificationID.strip()
    out.put({'BOTSID':rootelement,ns1+'ListReportOfReleaseNotice__{http://www.w3.org/2001/XMLSchema-instance}schemaLocation':'urn:kr:gov:kcs:data:standard:KCS_ListReportOfReleaseNoticeSchemaModule:1:0:0 ./schema/uncefact/data/KCS_ListReportOfReleaseNoticeSchemaModule_1.0.0_standard.xsd'})
    
    #Write to out by XML order
    out.put({'BOTSID':rootelement,ns1+'ScheduledOverdueGoodsDate':utils.isoDateFormat(ScheduledOverdueGoodsDate)})
    out.put({'BOTSID':rootelement,ns1+'CarryInMeasure':CarryInMeasure})
    out.put({'BOTSID':rootelement,ns1+'CarryInMeasure__measureUnitCode':'KG'})
    
    #Document
    out.put({'BOTSID':rootelement},{'BOTSID':ns1+'Document',ns2+'TypeCode':DocumentTypeCode})
    out.put({'BOTSID':rootelement},{'BOTSID':ns1+'Document',ns2+'FunctionTypeCode':DocumentFunctionTypeCode})
    out.put({'BOTSID':rootelement},{'BOTSID':ns1+'Document',ns2+'IssueDate':utils.isoDateFormat(DocumentIssueDate)})
    
    #UCR
    out.put({'BOTSID':rootelement},{'BOTSID':ns1+'UCR',ns2+'IdentificationID':UCRIdentificationID})
    
    #CustomsOffice
    out.put({'BOTSID':rootelement},{'BOTSID':ns1+'CustomsOffice',ns2+'OfficeCode':CustomsOfficeCode})
    out.put({'BOTSID':rootelement},{'BOTSID':ns1+'CustomsOffice',ns2+'CodeID':CustomsOfficeCodeID})
    
    #Warehouse
    out.put({'BOTSID':rootelement},{'BOTSID':ns1+'Warehouse',ns2+'CodeID':WarehouseCodeID})
    
    #AssociatedTransportDocument
    out.put({'BOTSID':rootelement},{'BOTSID':ns1+'AssociatedTransportDocument',ns2+'referenceID':AssociatedTransportDocumentReferenceID})
    
    #Consignor
    out.put({'BOTSID':rootelement},{'BOTSID':ns1+'Consignor'},{'BOTSID':ns2+'Party',ns2+'TypeCode':'5AB'})
    out.put({'BOTSID':rootelement},{'BOTSID':ns1+'Consignor'},{'BOTSID':ns2+'Party',ns2+'ID':ConsignorPartyID})
    out.put({'BOTSID':rootelement},{'BOTSID':ns1+'Consignor'},{'BOTSID':ns2+'Party',ns2+'Name':ConsignorPartyName})
    out.put({'BOTSID':rootelement},{'BOTSID':ns1+'Consignor'},{'BOTSID':ns2+'Party'},{'BOTSID':ns2+'Communication',ns2+'AddressID':ConsignorPartyCommunicationAddressID})
    out.put({'BOTSID':rootelement},{'BOTSID':ns1+'Consignor'},{'BOTSID':ns2+'Party'},{'BOTSID':ns2+'Communication',ns2+'TypeCode':'02'})
    out.put({'BOTSID':rootelement},{'BOTSID':ns1+'Consignor'},{'BOTSID':ns2+'Party'},{'BOTSID':ns2+'Communication',ns2+'AddressID':ConsignorPartyCommunicationTelephone})
    out.put({'BOTSID':rootelement},{'BOTSID':ns1+'Consignor'},{'BOTSID':ns2+'Party'},{'BOTSID':ns2+'Communication',ns2+'TypeCode':'01'})
    out.put({'BOTSID':rootelement},{'BOTSID':ns1+'Consignor'},{'BOTSID':ns2+'Party'},{'BOTSID':ns2+'Address'},{'BOTSID':ns2+'Postal',ns2+'PostCodeID':ConsignorPartyAddressPostalCodeID})
    
    #CarryInGoodsPackaging
    out.put({'BOTSID':rootelement},{'BOTSID':ns1+'CarryInGoodsPackaging',ns2+'Quantity':CarryInGoodsPackagingQuantity})
    
    
    
